package com.lanou.controller;

import com.github.pagehelper.PageInfo;
import com.lanou.bean.Account;
import com.lanou.bean.AdminInfo;
import com.lanou.bean.Role;
import com.lanou.service.AccountService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * Created by dllo on 18/3/13.
 */
@Controller
public class AccountController {
    @Resource
    private AccountService accountService;
    @RequestMapping(value = "accountlist")
    public String accountlist(){
        return "/account/account_list";
    }
    @ResponseBody
    @RequestMapping(value = "alist")
    public List<Account> accounts(){
        return accountService.findAccountAll();
    }
    @RequestMapping(value = "accountadd")
    public String accountadd(){
        return "/account/account_add";
    }
    @RequestMapping(value = "accountupdate")
    public String accountupdate(){
        return "/account/account_modi";
    }
    @RequestMapping(value = "accountDetail")
    public String accountDetail(){
        return "/account/account_detail";
    }
    @ResponseBody
    @RequestMapping(value = "accountUpdate")
    public void accountUpdate(@RequestParam("realName") String realName, @RequestParam("telephone") String telephone, @RequestParam("email") String email,@RequestParam("gender") String gender, @RequestParam("zipcode") String zipcode, @RequestParam("qq") String qq, @RequestParam("accountId") Integer accountId){
        accountService.accountUpdate(realName,telephone,email,gender,zipcode,qq,accountId);
    }
    @ResponseBody
    @RequestMapping(value = "accountAdd")
    public void accountAdd(@RequestParam("realName") String realName,@RequestParam("idcardNo") String idcardNo,@RequestParam("loginName") String loginName,@RequestParam("loginPasswd") String loginPasswd,@RequestParam("telephone") String telephone,Date createDate){
        createDate=new Date(System.currentTimeMillis());
        accountService.accountAdd(realName,idcardNo,loginName,loginPasswd,telephone,createDate);
    }
    @ResponseBody
    @RequestMapping(value = "accountPage")
    public PageInfo<Account> queryAccountByPage(@RequestParam("pagenum") Integer pageNo){
        return accountService.queryAccountByPage(pageNo,5);
    }
    @ResponseBody
    @RequestMapping(value = "findAccountById")
    public List<Account> findAccountById(@RequestParam("accountId") Integer accountId){
        return accountService.findAccountById(accountId);
    }
    @ResponseBody
    @RequestMapping(value = "deleteAccountAndService")
    public void deleteAccountAndService(@RequestParam("accountId") Integer accountId){
        accountService.deleteAccountAndService(accountId);
    }
    @ResponseBody
    @RequestMapping(value = "updateStatusById")
    public void updateStatusById(@RequestParam("status") String status,@RequestParam("accountId") Integer accountId){
        accountService.updateStatusById(status,accountId);
    }
}
